package com.njupt.towersusers.controller;


import com.njupt.towersusers.domain.Driver;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
//coming
@RestController
@RequestMapping("/usr")
@CrossOrigin("*")
public class DriverCtrl {
    @RequestMapping("/insertUser")
    public String insert(Driver driver,
                         MultipartFile usphoto,
                         MultipartFile drivercard){
        //调用服务类将文件保存为临时文件
        //再将临时文件上传到fastdfs文件服务器上 并获得服务器上的返回的图片路径和新图片名
        //再把服务器上的图片文件信息存放到driver对象中
        //再把driver对象存放到mysql数据库中
        return "{\"driverreg\": \"success\"}";
    }
    @RequestMapping("/userdel/{driverid}")
    public String del(@PathVariable("driverid")int driverid){
        System.out.println(driverid);
        return "{\"driverdestory\": \"success\"}";
    }
    @RequestMapping("/userMod")
    public String mod(Driver driver){
        return "{\"drivermodify\": \"success\"}";
    }
    @RequestMapping("/findUser")
    public List<Driver> findUser(int pageSize,int page){
        List<Driver> drs = new ArrayList<>();
        drs.add(Driver.builder().drivername("zs").driverid(12).driverage(40).build());
        drs.add(Driver.builder().drivername("ls").driverid(11).driverage(50).build());
        return drs;
    }
    @RequestMapping("/findUserByCondition")
    public List<Driver> findCond(Driver driver){
        List<Driver> drs = new ArrayList<>();
        drs.add(Driver.builder().drivername("zs").driverid(12).driverage(40).build());
        drs.add(Driver.builder().drivername("ls").driverid(11).driverage(50).build());
        return drs;
    }
}
